package com.example.mq.sender;
import com.example.dto.OrderMsg;
import com.example.mq.dto.Msg;
import com.example.mq.po.MsgDelayPO;
import com.example.mq.po.MsgPO;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

public interface IMsgSender
{
    /**
     * 批量发送消息
     *
     * @param msgList
     */
    void send(List<Object> msgList);

    /**
     * 发送单条消息
     *
     * @param msg
     */
    default void send(Object msg)
    {
        Objects.nonNull(msg);
        this.send(Arrays.asList(msg));
    }



    /*
     * 批量投递延迟消息
     * @param delayTime 延迟时间
     * @param delayTimeUnit 延迟时间单位
     * @param msgList 消息
     */
    void send(long delayTime, TimeUnit delayTimeUnit, List<Object> msgList);



    /*
     * 发送单条延迟消息
     * @param delayTime 延迟时间
     * @param delayTimeUnit 延迟时间单位
     * @param msg 消息
     */
    default void send(long delayTime, TimeUnit delayTimeUnit, Object msg)
    {
        this.send(delayTime, delayTimeUnit, Arrays.asList(msg));
    }

    /*
     * 投递重试
     * @param msgPO
     */
    void sendDelayRetry(MsgDelayPO msgDelayPO);

    /*
     * 投递重试
     * @param msgPO
     */
    void sendRetry(MsgPO msgPO);

    default void sendSequentialWithBody(String orderId, String exchange, String routingKey, OrderMsg msgBody)
    {
        this.sendSequentialMsg(orderId, exchange, routingKey, this.build(msgBody));
    }

    <T> Msg<T> build(T msgBody);


    void sendSequentialMsg(String busId, String exchange, String routingKey, Msg<?> msg);


}


